package com.kuzufang.modules.publish;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.kuzufang.R;
import com.kuzufang.base.BaseActivity;

/**
 * Created by songyuanjin on 2017/10/9.
 */

public class PublishActivity extends BaseActivity implements View.OnClickListener {
    private Toolbar mToolbar;
    private TextView mRoomTextView;
    private TextView mRoommateTextView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_publish);

        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        mToolbar.setTitle(R.string.activity_publish_title);
        setSupportActionBar(mToolbar);

        mRoomTextView = (TextView) findViewById(R.id.tv_find_room);
        mRoommateTextView = (TextView) findViewById(R.id.tv_find_roommate);

        ObjectAnimator roomXObjectAnimator = ObjectAnimator.ofFloat(mRoomTextView, "scaleX", 1.0f, 1.2f).setDuration(1600);
        ObjectAnimator roomYObjectAnimator = ObjectAnimator.ofFloat(mRoomTextView, "scaleY", 1.0f, 1.2f).setDuration(1600);
        roomXObjectAnimator.setRepeatCount(-1);
        roomYObjectAnimator.setRepeatCount(-1);
        roomXObjectAnimator.setRepeatMode(ValueAnimator.REVERSE);
        roomYObjectAnimator.setRepeatMode(ValueAnimator.REVERSE);

        ObjectAnimator roommateXObjectAnimator = ObjectAnimator.ofFloat(mRoommateTextView, "scaleX", 1.0f, 1.2f).setDuration(1600);
        ObjectAnimator roommateYObjectAnimator = ObjectAnimator.ofFloat(mRoommateTextView, "scaleY", 1.0f, 1.2f).setDuration(1600);
        roommateXObjectAnimator.setRepeatCount(-1);
        roommateYObjectAnimator.setRepeatCount(-1);
        roommateXObjectAnimator.setRepeatMode(ValueAnimator.REVERSE);
        roommateYObjectAnimator.setRepeatMode(ValueAnimator.REVERSE);
        roommateXObjectAnimator.setStartDelay(400);
        roommateYObjectAnimator.setStartDelay(400);

        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(roomXObjectAnimator, roomYObjectAnimator, roommateXObjectAnimator, roommateYObjectAnimator);
        //animatorSet.start();

        mRoomTextView.setOnClickListener(this);
        mRoommateTextView.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_find_room:
                startActivity(new Intent(PublishActivity.this, PublishFindRoomActivity.class));
                break;
            case R.id.tv_find_roommate:
                startActivity(new Intent(PublishActivity.this, PublishFindRoommateActivity.class));
                break;
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}
